<template>
  <div class="app-container">
    <el-form :model="selectForm" ref="queryForm" :inline="true">
      <el-form-item label="请输入验收单号">
        <el-input v-model="selectForm.acceptCode" placeholder="请输入验收单号" clearable size="small"
                  @keyup.enter.native="getList"/>
      </el-form-item>
      <el-form-item label="标题">
        <el-input v-model="selectForm.acceptTitle" placeholder="请输入标题" clearable size="small"
                  @keyup.enter.native="getList"/>
      </el-form-item>
      <el-form-item label="验收日期">
        <el-date-picker @keyup.enter.native="getList" v-model="date" size="small" value-format="yyyy-MM-dd"
                        type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"
                        @change="dateSelect"></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="getList" >搜索</el-button>
        <el-button type="success" icon="el-icon-plus" size="mini" @click="add" >添加</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="list.rows" border>
      <el-table-column align="center" type="index" label="序号" width="55"/>
      <el-table-column align="center" label="验收单号" property="acceptCode" width="150">
        <template slot-scope="scope" style="text-align: center">
          <el-button size="mini" type="text" @click="details(scope.row)" >
            {{scope.row.acceptCode}}
          </el-button>
        </template>
      </el-table-column>
      <el-table-column align="center" label="验收标题" property="acceptTitle"/>
      <!--      0805szw修改-->
      <el-table-column align="center" label="采购计划单号" property="planCode"/>
      <el-table-column align="center" label="创建人" property="createName"/>
<!--      0805szw修改-->
<!--      <el-table-column align="center" label="验收类别" property="acceptTypeName"/>-->
      <el-table-column align="center" label="验收人" property="acceptUserName"/>
      <el-table-column label="验收日期" align="center" width="180">
        <template slot-scope="scope">
          {{ parseTime(scope.row.acceptDate) }}
        </template>
      </el-table-column>
      <el-table-column align="center" label="验收描述" property="acceptDescribe" :show-overflow-tooltip="true"/>
      <el-table-column align="center" label="说明" property="remark" :show-overflow-tooltip="true"/>
      <el-table-column label="操作" align="center" width="200" >
        <template slot-scope="scope">
          <el-button size="mini" type="primary" icon="el-icon-edit" @click="edit(scope.row)">编辑</el-button>
          <el-button v-hasPermi="['purchaseGL:equipmentGL:delete']" size="mini" type="danger" icon="el-icon-delete" @click="del(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      :total="list.total?list.total:0"
      :page.sync="selectForm.pageNum"
      :limit.sync="selectForm.pageSize"
      @pagination="getList"
    />
    <equipment-add v-if="isAdd" :pid="aid" @subSetChane="addSetChane"></equipment-add>
    <equipment-des v-if="isDes" :pid="pid" @subSetChane="subSetChane"></equipment-des>
  </div>
</template>

<script>
  import { deviceAccept, deviceAcceptDel } from '@/api/purchase/index'
  import equipmentAdd from './equipmentAdd'
  import equipmentDes from './equipmentXQ'

  export default {
    name: 'Role',
    components:{
      equipmentAdd,
      equipmentDes
    },
    data() {
      return {
        loading: false,
        list: [],
        selectForm: {
          pageNum: 1,
          pageSize: 10,
          acceptCode: '',
          acceptTitle: '',
          beginDate: '',
          endDate: ''
        },
        date: '',

        isAdd:false,
        aid: null,
        isDes:false,
        pid:null
      }
    },
    created() {
      this.getList()
    },
    methods: {
      /** 查询列表 */
      async getList() {
        this.loading = true
        let res = await deviceAccept(this.selectForm)
        this.list = res
        this.loading = false
      },
      dateSelect() {
        this.selectForm.beginDate = this.date[0]
        this.selectForm.endDate = this.date[1]
      },
      /** 删除*/
      del(row) {
        this.$confirm('确定删除吗？', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(async() => {
          await deviceAcceptDel(row.id)
          this.$message.success('删除成功')
          this.getList()
        }).catch(() => {
          this.$message.info('取消删除')
        })
      },
      //采购计划
      add: function() {
        // this.$router.push({ path: '/purchaseGL/equipmentAdd', query: { userid: '55555' } })
        this.aid= null
        this.isAdd=true
      },
      addSetChane(info){
        this.isAdd=false
        this.aid=null
        if(info)this.getList()
      },
      edit(row){
        this.aid= row.id
        this.isAdd=true
      },
      //详情点击
      details: function(row) {
        // this.$router.push({ path: '/purchaseGL/equipmentXQ', query: { data: row.id } })
        this.pid=row.id
        this.isDes=true
      },
      subSetChane(){
        this.isDes=false
        this.pid=null
      }

    }
  }
</script>
